package logic

import (
	"context"
	"user_srv/models"

	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddPositionLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddPositionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddPositionLogic {
	return &AddPositionLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddPositionLogic) AddPosition(in *user.AddPositionRequest) (*user.AddPositionResponse, error) {
	// todo: add your logic here and delete this line

	var p models.Position
	p.PositionName = in.PositionName
	p.Category = in.Category
	p.Address = in.Address
	p.Salary = float64(in.Salary)
	p.WorkExperience = in.WorkExperience
	p.Graduate = in.Graduate
	p.Info = in.Info
	p.UserId = in.UserId

	err := p.AddPosition()
	if err != nil {
		logx.Error("发布失败", err)
		return nil, err
	}

	return &user.AddPositionResponse{PositionId: int64(p.ID)}, nil
}
